package com.xu.demo.filterPattern;

import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;

public class FilterChain {

    private List<IFilter> filters;

    public FilterChain(List<IFilter> filters) {
        this.filters = filters;
    }

    public List<Person> doFilter(List<Person> personList) {
        if (CollectionUtils.isEmpty(filters) || CollectionUtils.isEmpty(personList)) {
            return new ArrayList<>();
        }

        List<Person> afterFilterShapes = new ArrayList<>(personList);
        // 执行过滤
        for (IFilter filter : filters) {
            afterFilterShapes = filter.filterOperate(afterFilterShapes);
        }
        return afterFilterShapes;
    }
}
